package com.example.ibsp_demo.controller.create;

import com.example.ibsp_demo.mapper.user.UserMapper;
import com.example.ibsp_demo.pojo.entity.user.User;
import com.example.ibsp_demo.pojo.response.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "http://localhost:8080")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    // 获取当前登录用户信息
    @GetMapping("/current")
    public ResponseMessage<User> getCurrentUser(@RequestParam Integer uid) {
        User user = userMapper.selectByUid(uid);
        if (user == null) {
            return ResponseMessage.error(500, "用户不存在");
        }
        return ResponseMessage.success(user);
    }
}
